/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 * Description: 集合通信NPU侧标准notify
 */

#ifndef RTS_NOTIFY_H
#define RTS_NOTIFY_H

#include "notify_base.h"

namespace hccl {

class RtsNotify : public NotifyBase {
public:
    explicit RtsNotify(NotifyType notifyType);
    RtsNotify(NotifyType notifyType, HcclNotifyInfo notifyInfo);
    RtsNotify(NotifyType notifyType, const HcclSignalInfo &notifyInfo);
    ~RtsNotify();

    HcclResult Alloc() override;
    HcclResult Destroy() override;

    HcclResult Open() override;
    HcclResult Close() override;

    HcclResult Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut) override;
    HcclResult Post(Stream& stream, HcclDispatcher dispatcher, s32 stage) override;

    HcclResult Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut,
        u32 userRank, u32 remoteUserRank) override;
    HcclResult Post(Stream& stream, HcclDispatcher dispatcher, s32 stage,
        u32 remoteUserRank) override;

    HcclResult SetIpc() override;
    HcclResult Grant(s64 recvId) override;

    HcclResult GetNotifyData(HcclSignalInfo &notifyInfo) override
    {
        notifyInfo.resId = static_cast<u64>(id);
        notifyInfo.addr = address;
        notifyInfo.devId = devId;
        notifyInfo.tsId = tsId;
        notifyInfo.flag = flag;
        HCCL_DEBUG("GetNotifyData resId[%lld], addr[%llu], devId[%u], tsId[%u]", notifyInfo.resId,
            notifyInfo.addr, notifyInfo.devId, notifyInfo.tsId);
        return HCCL_SUCCESS;
    }

    HcclResult SetNotifyData(const HcclSignalInfo &notifyInfo) override
    {
        id = notifyInfo.resId;
        address = notifyInfo.addr;
        devId = notifyInfo.devId;
        tsId = notifyInfo.tsId;
        flag = notifyInfo.flag;
        HCCL_DEBUG("SetNotifyData resId[%lld], addr[%llu], devId[%u], tsId[%u]", id, address, devId, tsId);
        return HCCL_SUCCESS;
    }

    HcclResult GetNotifyOffset(u64 &notifyOffset) override
    {
        notifyOffset = notifyInfo_.ipcNotify.offset;
        return HCCL_SUCCESS;
    }

private:
    HcclResult UpdateNotifyInfo();

    bool isDestroyed{false};
    bool inchip{true};
    bool isLocal{true};

    u32 id{INVALID_UINT};
    u64 address{INVALID_U64};
    u32 size{INVALID_UINT};
    u32 devId{INVALID_UINT};
    u32 tsId{INVALID_UINT};
    u32 flag{INVALID_UINT};
};

}

#endif // RTS_NOTIFY_H
